FROM node:alpine 

ENV HOME=/home/sophia
ENV APP=sophia
ENV NODE_ENV production

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup -S $APP && adduser -S $APP -G $APP
RUN mkdir -p $HOME
WORKDIR $HOME


# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk add --no-cache libc6-compat
COPY package.json package-lock.json ./
RUN npm config set registry http://registry.npm.taobao.org
RUN npm install -g npm@latest
RUN npm install

# copy source code
COPY . .

RUN npm run build

RUN chown -R $APP:$APP $HOME
USER $APP

RUN chmod u+x ./entrypoint.prod.sh

ENTRYPOINT ["./entrypoint.prod.sh"]